package interfaz;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.Font;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JTextField;
import java.awt.GridLayout;
import java.awt.CardLayout;
import javax.swing.JPanel;
import java.awt.Insets;
import java.awt.Choice;
import javax.swing.JScrollBar;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;
import javax.swing.Action;

import mundo.ISistema;
import mundo.Sistema;

import java.awt.event.ActionListener;

public class Interfaz {

	private JFrame frmRcv;
	private JPanel panel;
	private JLabel lblSentido;
	private JLabel lblCiudad;
	private JTextField txtDireccion;
	private JTextField txtBogota;
	private JLabel lblSentido_1;
	private JPanel panel_1;
	private JRadioButton rdbtnNortesur;
	private JRadioButton rdbtnSurnorte;
	private JRadioButton rdbtnOesteeste;
	private JRadioButton rdbtnEsteoeste;
	private JLabel lblMotivo;
	private JTextField textField;
	private JButton btnOk;
	
	private static ISistema sis;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Interfaz window = new Interfaz();
					sis=new Sistema();
					window.frmRcv.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Interfaz() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmRcv = new JFrame();
		frmRcv.setTitle("RCV");
		frmRcv.setResizable(false);
		frmRcv.setAlwaysOnTop(true);
		frmRcv.setBounds(100, 100, 310, 293);
		frmRcv.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmRcv.getContentPane().setLayout(new BorderLayout(0, 0));
		
		JLabel lblRedDeColaboracin = new JLabel("Red de Colaboracion Vial");
		lblRedDeColaboracin.setFont(new Font("Trebuchet MS", Font.PLAIN, 26));
		frmRcv.getContentPane().add(lblRedDeColaboracin, BorderLayout.NORTH);
		
		panel = new JPanel();
		frmRcv.getContentPane().add(panel, BorderLayout.SOUTH);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[]{66, 36, 43, 0};
		gbl_panel.rowHeights = new int[]{14, 0, 0, 0, 0, 0, 0, 0, 0};
		gbl_panel.columnWeights = new double[]{1.0, 1.0, 0.0, Double.MIN_VALUE};
		gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		panel.setLayout(gbl_panel);
		
		lblCiudad = new JLabel("Ciudad");
		GridBagConstraints gbc_lblCiudad = new GridBagConstraints();
		gbc_lblCiudad.anchor = GridBagConstraints.EAST;
		gbc_lblCiudad.insets = new Insets(0, 0, 5, 5);
		gbc_lblCiudad.gridx = 0;
		gbc_lblCiudad.gridy = 0;
		panel.add(lblCiudad, gbc_lblCiudad);
		
		txtBogota = new JTextField();
		txtBogota.setEditable(false);
		txtBogota.setText("BOGOTA");
		GridBagConstraints gbc_txtBogota = new GridBagConstraints();
		gbc_txtBogota.insets = new Insets(0, 0, 5, 5);
		gbc_txtBogota.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtBogota.gridx = 1;
		gbc_txtBogota.gridy = 0;
		panel.add(txtBogota, gbc_txtBogota);
		txtBogota.setColumns(10);
		
		lblSentido = new JLabel("Direccion");
		GridBagConstraints gbc_lblSentido = new GridBagConstraints();
		gbc_lblSentido.anchor = GridBagConstraints.NORTHEAST;
		gbc_lblSentido.insets = new Insets(0, 0, 5, 5);
		gbc_lblSentido.gridx = 0;
		gbc_lblSentido.gridy = 1;
		panel.add(lblSentido, gbc_lblSentido);
		
		txtDireccion = new JTextField();
		GridBagConstraints gbc_txtDireccion = new GridBagConstraints();
		gbc_txtDireccion.insets = new Insets(0, 0, 5, 5);
		gbc_txtDireccion.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtDireccion.gridx = 1;
		gbc_txtDireccion.gridy = 1;
		panel.add(txtDireccion, gbc_txtDireccion);
		txtDireccion.setColumns(10);
		
		lblMotivo = new JLabel("Motivo");
		GridBagConstraints gbc_lblMotivo = new GridBagConstraints();
		gbc_lblMotivo.anchor = GridBagConstraints.EAST;
		gbc_lblMotivo.insets = new Insets(0, 0, 5, 5);
		gbc_lblMotivo.gridx = 0;
		gbc_lblMotivo.gridy = 2;
		panel.add(lblMotivo, gbc_lblMotivo);
		
		textField = new JTextField();
		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.insets = new Insets(0, 0, 5, 5);
		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField.gridx = 1;
		gbc_textField.gridy = 2;
		panel.add(textField, gbc_textField);
		textField.setColumns(10);
		
		lblSentido_1 = new JLabel("Sentido");
		GridBagConstraints gbc_lblSentido_1 = new GridBagConstraints();
		gbc_lblSentido_1.anchor = GridBagConstraints.EAST;
		gbc_lblSentido_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblSentido_1.gridx = 0;
		gbc_lblSentido_1.gridy = 3;
		panel.add(lblSentido_1, gbc_lblSentido_1);
		
		panel_1 = new JPanel();
		GridBagConstraints gbc_panel_1 = new GridBagConstraints();
		gbc_panel_1.anchor = GridBagConstraints.NORTH;
		gbc_panel_1.insets = new Insets(0, 0, 5, 5);
		gbc_panel_1.fill = GridBagConstraints.HORIZONTAL;
		gbc_panel_1.gridx = 1;
		gbc_panel_1.gridy = 3;
		panel.add(panel_1, gbc_panel_1);
		GridBagLayout gbl_panel_1 = new GridBagLayout();
		gbl_panel_1.columnWidths = new int[]{0, 0, 0};
		gbl_panel_1.rowHeights = new int[]{0, 0, 0};
		gbl_panel_1.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
		gbl_panel_1.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
		panel_1.setLayout(gbl_panel_1);
		
		rdbtnNortesur = new JRadioButton("Norte-Sur");
		GridBagConstraints gbc_rdbtnNortesur = new GridBagConstraints();
		gbc_rdbtnNortesur.insets = new Insets(0, 0, 5, 5);
		gbc_rdbtnNortesur.gridx = 0;
		gbc_rdbtnNortesur.gridy = 0;
		
		panel_1.add(rdbtnNortesur, gbc_rdbtnNortesur);
		
		rdbtnOesteeste = new JRadioButton("Oeste-Este");
		GridBagConstraints gbc_rdbtnOesteeste = new GridBagConstraints();
		gbc_rdbtnOesteeste.insets = new Insets(0, 0, 5, 0);
		gbc_rdbtnOesteeste.gridx = 1;
		gbc_rdbtnOesteeste.gridy = 0;
		panel_1.add(rdbtnOesteeste, gbc_rdbtnOesteeste);
		
		rdbtnSurnorte = new JRadioButton("Sur-Norte");
		GridBagConstraints gbc_rdbtnSurnorte = new GridBagConstraints();
		gbc_rdbtnSurnorte.insets = new Insets(0, 0, 0, 5);
		gbc_rdbtnSurnorte.gridx = 0;
		gbc_rdbtnSurnorte.gridy = 1;
		panel_1.add(rdbtnSurnorte, gbc_rdbtnSurnorte);
		
		rdbtnEsteoeste = new JRadioButton("Este-Oeste");
		GridBagConstraints gbc_rdbtnEsteoeste = new GridBagConstraints();
		gbc_rdbtnEsteoeste.gridx = 1;
		gbc_rdbtnEsteoeste.gridy = 1;
		panel_1.add(rdbtnEsteoeste, gbc_rdbtnEsteoeste);
		
		rdbtnSurnorte.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				rdbtnNortesur.setSelected(false);
				rdbtnEsteoeste.setSelected(false);
				rdbtnOesteeste.setSelected(false);
			}
			});
		
		rdbtnNortesur.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				rdbtnSurnorte.setSelected(false);
				rdbtnEsteoeste.setSelected(false);
				rdbtnOesteeste.setSelected(false);
			}
			});
		
		rdbtnEsteoeste.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				rdbtnSurnorte.setSelected(false);
				rdbtnNortesur.setSelected(false);
				rdbtnOesteeste.setSelected(false);
			}
			});
		
		rdbtnOesteeste.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				rdbtnSurnorte.setSelected(false);
				rdbtnNortesur.setSelected(false);
				rdbtnEsteoeste.setSelected(false);
			}
			});
		
		btnOk = new JButton("Ok");
		
		
		
		btnOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				String dir=txtDireccion.getText();
				sis.agregarReporteCiudad("Bogota", dir, darInfo(),textField.getText());
				frmRcv.setVisible(false);
				new RESULTADO(frmRcv,sis.darRep("Bogota", dir));
			}
		});
		
		GridBagConstraints gbc_btnOk = new GridBagConstraints();
		gbc_btnOk.insets = new Insets(0, 0, 5, 5);
		gbc_btnOk.gridx = 1;
		gbc_btnOk.gridy = 6;
		panel.add(btnOk, gbc_btnOk);
	}

//	private class SwingAction extends AbstractAction {
//		public SwingAction() {
//			putValue(NAME, "SwingAction");
//			putValue(SHORT_DESCRIPTION, "Some short description");
//		}
//		public void actionPerformed(ActionEvent e) 
//		{
//		}
//	}
	
	public String darInfo()
	{
		if(rdbtnEsteoeste.isSelected())
		{
			return "Este-Oeste";
		}
		else if(rdbtnOesteeste.isSelected())
		{
			return "Oeste-Este";
		}
		else	if(rdbtnNortesur.isSelected())
		{
			return "Norte-Sur";
		}
			else	if(rdbtnSurnorte.isSelected())
		{
			return "Sur-Norte";
		}
		return null;
	}
}
